﻿$("#MainNav,#TopNav,#BottomNav").datagrid({
    fit: true,
    fitColumns: true,
    striped: true,
    rownumbers: true,
    remoteSort: false,
    singleSelect: true,
    idField: "ID",
    columns: [[{
        title: "导航名称",
        field: "NavName",
        width: 12
    }, {
        title: "链接地址",
        field: "NavUrl",
        width: 71
    }, {
        title: "排序",
        field: "Sort",
        width: 5
    }, {
        field: 'action',
        title: '编辑',
        width: 12,
        align: 'center',
        formatter: function (value, row, index) {
            return '<a href="#" onclick="edit(' + row.ID + ')">编辑</a>&nbsp;|&nbsp;<a href="#" onclick="del(' + row.ID + ')">删除</a>';
        }
    }]]
});
$.post(
    "/Admin/Nav/GetNavList?r=" + Math.random(),
    function (data) {
        $("#MainNav").datagrid({
            data: filterData(data, 0)
        });
        $("#TopNav").datagrid({
            data: filterData(data, 1)
        });
        $("#BottomNav").datagrid({
            data: filterData(data, 2)
        });
    });
function filterData(data, filter) {
    var tempData = { rows: [], total: 0 };
    for (var i = 0; i < data.rows.length; i++) {
        if (data.rows[i].NavPosition == filter) {
            tempData.rows.push(data.rows[i]);
        }
    }
    tempData.total = tempData.rows.length;
    return tempData;
}
function add() {
    location.href = "/Admin/Nav/Create?current=1&r=" + Math.random();
}
function edit(id) {
    location.href = "/Admin/Nav/Edit/" + id + "?current=1&r=" + Math.random();
}
function del(id) {
    $.messager.confirm('警告', '确定删除?', function (r) {
        if (r)
            location.href = "/Admin/Nav/Delete/" + id + "?current=1&r=" + Math.random();
    });
}